#include <scwrapper.h>
#include <foolibc.h>

const int myport = 1;


void stdout(char *string, int port_dest) 
{
	struct message m;
	m.data = string;
	m.size = my_strlen(string)+1;
	m.dest_port = port_dest;
	m.src_port = myport;

	long status;
	do {
		status = send_msg(&m);
	} while (status != ALL_OK);	// send until we get succes, but only send once
}

void processing(char *string) {
	int i;
	int len = my_strlen(string);
	for (i = 0; i < len; i++) {
		if (string[i] == 'j')
			string[i] = 'i';
	}
	stdout(string, 2);
}

void stdin()
{
	struct message m;
	if (retrieve_msg(&m, myport) == 0) {
		processing(m.data);
		free((long) m.data);
	}
	terminate();
}

int main(int argc, char* argv[])
{
	const int status = create_mailbox(stdin, myport);
	if (status != ALL_OK) {
		while (1) {prints("Could not create mailbox1\n\0");}
	}
	
	while (1) {pause(100);}
}
